package com.atguigu.tingshu.account.listener;/*
 * title:
 * author:
 * date:
 * description:
 * */

import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import io.micrometer.common.util.StringUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AccountListener {
    @Resource
    private UserAccountService userAccountService;

    @KafkaListener(topics = KafkaConstant.QUEUE_USER_REGISTER)
    public void listen(String userId, Acknowledgment ack){
        if (StringUtils.isBlank(userId)){
            ack.acknowledge();
            return;
        }
        userAccountService.saveUserAccount(Long.valueOf(userId));
        ack.acknowledge();
    }
}
